package com.rainbow.seata.api.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.rainbow.seata.api.mapper.StorageMapper;
import com.rainbow.seata.common.model.Storage;
import com.rainbow.seata.common.service.StorageService;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Service
@Component
@Slf4j
public class StorageServiceImpl implements StorageService {
    @Autowired
    private StorageMapper storageMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String getStore(String name) {
        log.info("storage-xid: " + RootContext.getXID());
        Storage storage = new Storage();
        storage.setCommodityCode("code:"+name);
        storage.setName(name);
        storageMapper.insert(storage);
        return "addStore:"+storage.getId();
    }
}
